﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TradingServer.Core.Entities
{
	public class OrderComparer : IComparer<Order>
	{
		#region IComparer<Order> Members

		public int Compare(Order x, Order y)
		{
			if (x.Equals(y)) return 0;
			if (x.Price != y.Price)
			{
				if (x.Price == null & y.Price != null) return -1;
				if (x.Price != null & y.Price == null) return 1;
				return x.Price.Value > y.Price.Value ? 1 : x.Price.Value < y.Price.Value ? -1 : 0;
			}
			// если цены равны, сравниваем даты
			return x.CreateDate.CompareTo(y.CreateDate);
		}

		#endregion
	}
}
